package com.ruoyi.system.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseIdEntity;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;

import java.util.Date;

/**
 * 变电站设备信息对象 s_substation_device
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@Data
@ApiModel(value = "SSubstationDevice", description = "变电站设备信息对象")
public class SSubstationDevice extends BaseIdEntity
{
    private static final long serialVersionUID = 1L;

    /** id */
    @ApiModelProperty("id")
    private String id;

    /** 变电站id */
    @Excel(name = "变电站id")
    @ApiModelProperty("变电站id")
    private String substationId;

    /** 变电站名称 */
    @TableField(exist = false)
    @ApiModelProperty("变电站名称")
    private String substationName;

    /** 设备编号 */
    @Excel(name = "设备编号")
    @ApiModelProperty("设备编号")
    private String deviceNo;

    /** 设备名称 */
    @Excel(name = "设备名称")
    @ApiModelProperty("设备名称")
    private String deviceName;

    /** 开关编号 */
    @Excel(name = "开关编号")
    @ApiModelProperty("开关编号")
    private String switchNo;

    /** 调度名称 */
    @Excel(name = "调度名称")
    @ApiModelProperty("调度名称")
    private String scheduleName;

    /** 装置版本号 */
    @Excel(name = "装置版本号")
    @ApiModelProperty("装置版本号")
    private String deviceVersion;

    /** 校验码 */
    @Excel(name = "校验码")
    @ApiModelProperty("校验码")
    private String checkCode;

    /** 电压等级Id */
    @Excel(name = "电压等级Id")
    @ApiModelProperty("电压等级Id")
    private String voltageLevel;

    /** 二维码图片地址 */
    @Excel(name = "二维码图片地址")
    @ApiModelProperty("二维码图片地址")
    private String qrCodeUrl;

    /** 电压等级值 */
    @TableField(exist = false)
    @ApiModelProperty("电压等级值")
    private String voltageLevelValue;

    /** 保护型号 */
    @Excel(name = "保护型号")
    @ApiModelProperty("保护型号")
    @TableField(exist = false)
    private String protectDeviceModel;

    /** CT变比 */
    @Excel(name = "CT变比")
    @ApiModelProperty("CT变比")
    private String ctTransformationRatio;

    /** PT变比 */
    @Excel(name = "PT变比")
    @ApiModelProperty("PT变比")
    private String ptTransformationRatio;

    @TableField(exist = false)
    @ApiModelProperty("区域id")
    private String areaId;

    @TableField(exist = false)
    @ApiModelProperty("区域名称")
    private String areaName;

    /** 创建者 */
    @TableField(fill = FieldFill.UPDATE)
    @ApiModelProperty("创建者")
    private String createBy;

    /** 创建时间 */
    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /** 更新者 */
    @TableField(fill = FieldFill.UPDATE)
    @ApiModelProperty("更新者")
    private String updateBy;

    /** 更新时间 */
    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    public <T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> wrapper=new QueryWrapper<>();

        wrapper.eq(StringUtils.isNotEmpty(id),"d.id" , id);
        wrapper.eq(StringUtils.isNotEmpty(substationId),"d.substation_id" , substationId);
        wrapper.like(StringUtils.isNotEmpty(deviceNo),"d.device_no" , deviceNo);
        wrapper.like(StringUtils.isNotEmpty(deviceName),"d.device_name" , deviceName);
        wrapper.like(StringUtils.isNotEmpty(switchNo),"d.switch_no" , switchNo);
        wrapper.like(StringUtils.isNotEmpty(scheduleName),"d.schedule_name" , scheduleName);
        wrapper.like(StringUtils.isNotEmpty(deviceVersion),"d.device_version" , deviceVersion);
        wrapper.like(StringUtils.isNotEmpty(checkCode),"d.check_code" , checkCode);
        wrapper.eq(StringUtils.isNotEmpty(voltageLevel),"d.voltage_level" , voltageLevel);
        wrapper.like(StringUtils.isNotEmpty(ctTransformationRatio),"d.CT_transformation_ratio" , ctTransformationRatio);
        wrapper.like(StringUtils.isNotEmpty(ptTransformationRatio),"d.PT_transformation_ratio" , ptTransformationRatio);
        wrapper.and(StringUtils.isNotEmpty(getKeyword()),v -> v.like("d.device_name" , getKeyword())
                .or().like("s.substation_name" , getKeyword()));
        wrapper.orderByDesc("d.create_time");
        return wrapper;
    }

}
